package cn.cupk.logsystem.log.factoryPattern;

import cn.cupk.logsystem.log.observerPattern.Handler;

import java.io.IOException;


public class HandlerFactory {
    public static Handler createHandler(HandlerType type) {
        switch (type) {
            case CONSOLE:
                return new ConsoleHandler();
            case DATABASE:
                return new DatabaseHandler();
            case FILE:
                try {
                    return new FileHandler("log.txt", true);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            case XML:
                try {
                    return new XmlHandler("log.xml", true);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            default:
                throw new IllegalArgumentException("Unknown handler type");
        }
    }
}

